package b2.widget.vip
{
	import b2.config.*;
	import b2.net.*;
	import b2.util.*;
	import b2.widget.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.text.*;
	
	public class VipPrivilegesDialog extends Sprite
	{
		private const dailyPresent:Array = ["5_2,6_2", "5_4,6_4", "5_6,6_6", "5_6,6_6,7_2,8_2", "5_6,6_6,7_4,8_4", "5_6,6_6,7_6,8_6", "5_7,6_7,7_7,8_7"];
		
		public function VipPrivilegesDialog()
		{
			super();
			//对话框背景
			var VipPrivilegesDialogBgr:Class = ResourceHelper.getInstance().getClassByName("VipPrivilegesDialogBgr");
			addChild(new VipPrivilegesDialogBgr());
			//关闭按钮
			var VipButtonClose1:Class = ResourceHelper.getInstance().getClassByName("VipButtonClose1");
			var VipButtonClose2:Class = ResourceHelper.getInstance().getClassByName("VipButtonClose2");
			var closeIcon:ImgSwitchIcon = new ImgSwitchIcon(VipButtonClose1, VipButtonClose2);
			closeIcon.x = 490;
			closeIcon.y = 15;
			addChild(closeIcon);
			closeIcon.addEventListener(MouseEvent.CLICK, onButtonCloseClick);
			//开通黄钻
			var vipButtonOpen:VipButtonOpen = new VipButtonOpen();
			vipButtonOpen.x = 250;
			vipButtonOpen.y = 415;
			addChild(vipButtonOpen);
			//开通年费黄钻
			var vipButtonOpenYear:VipButtonOpenYear = new VipButtonOpenYear();
			vipButtonOpenYear.x = 380;
			vipButtonOpenYear.y = 415;
			addChild(vipButtonOpenYear);
			var objectConfig:CommonObjConfig;
			var ObjectImage:Class;
			var objectSprite:Sprite;
			var objectTitleText:TextField;
			var objectNumText:TextField;
			//顶部文字
			var topTitleText:TextField = new TextField();
			topTitleText.selectable = false;
        	topTitleText.autoSize = TextFieldAutoSize.LEFT;
			topTitleText.defaultTextFormat = new TextFormat("微软雅黑", 15, 0x8F470E, true);
			topTitleText.width = 200;
			topTitleText.text = "成为黄钻贵族，每天将获得黄钻等级礼包，等级越高礼包越大。\n更有黄钻活动特权、升级双倍奖励、全场商品8折等特权让你享乐不停！";
			topTitleText.x = 35;
			topTitleText.y = 60;
			addChild(topTitleText);
			//每日礼物
			for (var i:int = 0; i < 7; i++)
			{
				var dailyPresentStrs:Array = dailyPresent[i].split(",");
				var dailyPresent:Sprite = new Sprite();
				var VipIconImg:Class = ResourceHelper.getInstance().getClassByName("VipIcon" + (i + 1));
				var vipIcon:Sprite = new VipIconImg();
				vipIcon.width = 30;
				vipIcon.scaleY = vipIcon.scaleX;
				dailyPresent.addChild(vipIcon);
				for (var j:int = 0; j < dailyPresentStrs.length; j++)
				{
					var presentStrs:Array = dailyPresentStrs[j].split("_");
					var objectIndex:int = presentStrs[0];
					var objectNum:int = presentStrs[1];
					objectConfig = Config.objectConfigs[objectIndex];
					//物品图片
					ObjectImage = ResourceHelper.getInstance().getClassByName(objectConfig.iconImage);
					objectSprite = new ObjectImage();
					objectSprite.width = 30;
					objectSprite.scaleY = objectSprite.scaleX;
					objectSprite.x = 80 * j + 35;
					objectSprite.y = -5;
					dailyPresent.addChild(objectSprite);
					//物品名字
					objectTitleText = new TextField();
					objectTitleText.selectable = false;
		        	objectTitleText.autoSize = TextFieldAutoSize.LEFT;
					objectTitleText.defaultTextFormat = new TextFormat("微软雅黑", 12, 0x8F470E);
					objectTitleText.x = 80 * j + 62;
					objectTitleText.y = -5;
					objectTitleText.text = objectConfig.name;
					dailyPresent.addChild(objectTitleText);
					//物品个数
					objectNumText = new TextField();
					objectNumText.selectable = false;
		        	objectNumText.autoSize = TextFieldAutoSize.LEFT;
					objectNumText.defaultTextFormat = new TextFormat("微软雅黑", 12, 0x8F470E);
					objectNumText.x = 80 * j + 77;
					objectNumText.y = 8;
					objectNumText.text = "×" + objectNum;
					dailyPresent.addChild(objectNumText);
				}
				dailyPresent.mouseChildren = false;
				dailyPresent.x = 25;
				dailyPresent.y = i * 34 + 178;
				addChild(dailyPresent);
			}
			var yearPresent:Sprite = new Sprite();
			//年费礼物
			objectConfig = Config.objectConfigs[CommonObjConfig.HERO_VERT];
			//物品图片
			ObjectImage = ResourceHelper.getInstance().getClassByName("HeroVertInside");
			objectSprite = new ObjectImage();
			objectSprite.width = 100;
			objectSprite.scaleY = objectSprite.scaleX;
			objectSprite.x = 5;
			yearPresent.addChild(objectSprite);
			//物品名字
			objectTitleText = new TextField();
			objectTitleText.selectable = false;
        	objectTitleText.autoSize = TextFieldAutoSize.LEFT;
			objectTitleText.defaultTextFormat = new TextFormat("微软雅黑", 18, 0x8F470E, true);
			objectTitleText.x = 15;
			objectTitleText.y = 120;
			objectTitleText.text = objectConfig.name;
			yearPresent.addChild(objectTitleText);
			//物品个数
			objectNumText = new TextField();
			objectNumText.selectable = false;
        	objectNumText.autoSize = TextFieldAutoSize.LEFT;
			objectNumText.defaultTextFormat = new TextFormat("微软雅黑", 18, 0x8F470E, true);
			objectNumText.x = 30;
			objectNumText.y = 140;
			objectNumText.text = "×10";
			yearPresent.addChild(objectNumText);
			yearPresent.mouseChildren = false;
			yearPresent.x = 400;
			yearPresent.y = 230;
			addChild(yearPresent);
		}
		
		public function onButtonCloseClick(event:MouseEvent):void
		{
			close();
		}
		
		public function close():void
        {
        	if (this.parent != null)
        	{
        		this.parent.removeChild(this);
        	}
        }
	}
}